function toHex(char: string = ''): string {
  return char.charCodeAt(0).toString(16)
}

export default {
  encode(str: string = ''): string {
    return str.split('').map(toHex).join('')
  },

  decode(hex: string = ''): string {
    const result: string[] = []
    for (let i = 0; i < hex.length; i += 2) {
      result.push(String.fromCharCode(parseInt(hex.substr(i, 2), 16)))
    }
    return result.join('')
  }
}
